<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // ['1',3,5,6,7,88999,11,55,'1']
      // 多种方法 forEach  findIndex filter new Set()
      let arr = ['1', 3, 55, 6, 7, 88999, 11, 55, '1']
      const newArr = JSON.parse(JSON.stringify(arr))
      // console.log(newArr)
      // 一种
      MostNumber(newArr)
      function MostNumber(array) {
        let a = {}
        let m = 0
        let maxele = null
        for (let i = 0; i < array.length; i++) {
          a[array[i]] == undefined ? (a[array[i]] = 1) : a[array[i]]++
          if (a[array[i]] > m) {
            maxele = array[i]
          }
        }
        return `次数最多的为:${maxele}`
      }

      console.log(MostNumber(newArr))

      // 二种
      let obj = {}
      newArr.forEach(function (item, index) {
        obj[item] = newArr[index]
      })
      console.log(obj)

      // 三种
      let newArr2 = newArr.filter(function (item, index) {
        // console.log(item)
        return newArr.indexOf(item) === index
      })

      console.log(newArr2)

      // findIndex
    const aa =  newArr.filter((item, index, a) => (
        a.findIndex((value, index2, newArr) => (item.value === item.value)) === index
      ))
      console.log(aa)

      // Set()
      let s = [...new Set(arr)]
      console.log(s)
    </script>
  </body>
</html>
